package cn.itacst.myServlet;

import javax.servlet.ServletException;
import javax.servlet.ServletInputStream;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

@WebServlet("/my2")
public class MyServlet2 extends HttpServlet {


    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("MyServlet2类中doGet方法执行了");


    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("MyServlet2类中doPost方法执行了");

        req.setCharacterEncoding("UTF-8");
        String username = req.getParameter("username");
        String addr = req.getParameter("addr");

        System.out.println("姓名:"+username +";addr:"+addr);

        ServletInputStream inputStream = req.getInputStream();
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"));

        System.out.println(bufferedReader);

        System.out.println("bufferedReader.readLine():"+bufferedReader.readLine());

        String line = null;
        while ((line = bufferedReader.readLine()) != null) {
            System.out.println(line);
        }

        System.out.println("post方法执行完成了");


    }
}
